<script setup lang='ts'>
import { ref, watch } from 'vue'
const props = withDefaults(defineProps<{
    rotationValue?: [number, number, number],
}>(), { rotationValue: () => [0, 0, 0] })

const emits = defineEmits([
    "update:rotationValue"
]);
const longitude = ref()
const latitude = ref()
const height = ref()
watch(() => props.rotationValue, (val) => {
    longitude.value = val[0].toFixed(2)
    latitude.value = val[1].toFixed(2)
    height.value = val[2].toFixed(2)
}, { immediate: true })
const update = (e: any, numberValues: [number, number, number] | undefined, num: number) => {
    if (numberValues === undefined) return
    let numberArr = [...numberValues]
    numberArr[num] = Number(e.target.value)
    emits("update:rotationValue", numberArr)
}
</script>

<template>
    <div class="rotation">
        <div class="input2" style="margin-bottom: 6px;">
            <label for=""> {{ '偏航角' }}</label>
            <input type="number" class="input_number" :value="longitude" @blur="update($event, rotationValue, 0)"
                @keydown.enter="update($event, rotationValue, 0)" step="0.01" placeholder="请输入偏航角" />
            <span style="position: absolute;right: 5px;top: 2px;">°</span>
        </div>
        <div class="input2" style="margin-bottom: 6px;">
            <label for=""> {{ '俯仰角' }}</label>
            <input type="number" class="input_number" :value="latitude" @blur="update($event, rotationValue, 1)"
                @keydown.enter="update($event, rotationValue, 1)" step="0.01" placeholder="请输入俯仰角" />
            <span style="position: absolute;right: 5px;top: 2px;">°</span>
        </div>
        <div class="input2">
            <label for=""> {{ '翻滚角' }}</label>
            <input type="number" class="input_number" :value="height" @blur="update($event, rotationValue, 2)"
                @keydown.enter="update($event, rotationValue, 2)" step="0.01" placeholder="请输入翻滚角" />
            <span style="position: absolute;right: 5px;top: 2px;">°</span>
        </div>
    </div>
</template>

<style scoped>
.rotation {
    width: 100%;
    border-top: 1px solid #111111;
    border-bottom: 1px solid #111111;
    padding-top: 10px;
    padding-bottom: 10px;
}

.input2 {
    width: 100%;
    display: flex;
    align-items: center;
    font-size: 14px;
    line-height: 26px;
    color: rgba(230, 230, 230, 1);
    position: relative;
}

.input2>label {
    display: inline-block;
    width: 70px;
    height: 26px;
    font-family: SourceHanSansCN, SourceHanSansCN;
    font-weight: 400;
    text-align: left;
}

.input2>input {
    display: inline-block;
    /* width: 190px; */
    flex: 1;
    height: 26px;
    background: rgba(28, 28, 29, 0.6);
    border-radius: 4px;
    border: 1px solid #3b3c40;
    margin-right: 0;
    color: rgba(230, 230, 230, 1);
    padding-left: 11px;
    box-sizing: border-box;
}

.input2>input:hover {
    border: 1px solid rgba(44, 104, 247, 1);
}

.input2>input:focus {
    border: 1px solid #2c68f7;
}

.input_number::-webkit-outer-spin-button,
.input_number::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

.input_number[type="number"] {
    -moz-appearance: textfield;
}
</style>
